<template>
<h1>员工列表练习</h1>
  <input type="text" v-model="user.name" placeholder="name">
  <input type="text" v-model="user.salary" placeholder="salary">
  <input type="text" v-model="user.job" placeholder="job">
  <button @click="add">add</button>
  <table border="1px">
    <tr>
      <th>编号</th>
      <th>name</th>
      <th>salary</th>
      <th>job</th>
    </tr>
    <tr v-for="(item,index) in arr">
      <td>{{index+1}}</td>
      <td>{{item.name}}</td>
      <td>{{item.salary}}</td>
      <td>{{item.job}}</td>
    </tr>

  </table>

</template>
<script setup>
import {ref} from "vue";

const user=ref({
  name:'',
  salary:'',
  job:''
});
const arr=ref([]);
const add=()=>{
  if (user.value.name.trim()==''||user.value.salary.trim()==''||user.value.job.trim()=='') {
    alert('输入内容不能为空');
    return;
  }
  arr.value.push(user.value);
  user.value={
    name:'',
    salary:'',
    job:''

  }
}

</script>


<style scoped>

</style>